package com.zzyl.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;
    @Override
    public List<NursingLevelVo> getAll() {
        List<NursingLevel> all = nursingLevelMapper.findAll();
        System.out.println(all);
        List<NursingLevelVo> nursingLevelVos = BeanUtil.copyToList(all, NursingLevelVo.class);
        return nursingLevelVos;
    }

    @Override
    public void add(NursingLevelDto nursingLevelDto) {
        NursingLevel bean = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.insert(bean);
    }

    @Override
    public PageResponse<NursingLevelVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingLevel> nursingLevels= nursingLevelMapper.findPage(name,status);
        return PageResponse.of(nursingLevels, NursingLevelVo.class);
    }

    @Override
    public NursingLevelVo selectById(Integer id) {
        NursingLevel byId = nursingLevelMapper.findById(id);

        return BeanUtil.toBean(byId, NursingLevelVo.class);
    }

    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel bean = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.update(bean);
    }

    @Override
    public void delete(Long id) {
        nursingLevelMapper.delete(id);
    }

    @Override
    public void able(Long id, Integer status) {
        nursingLevelMapper.able(id,status);
    }
}
